﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using UCS.XNA.Utils;
using UCS.XNA.Utils.Geometries;

namespace DivideAndConquer.States.InGame
{
    public class WallPreview : IRectangle
    {
        #region Constants

        private const float HEIGHT = 7f;

        #endregion

        #region Private Members

        private Texture2D _texture;

        #endregion

        #region Attributes and Properties

        private float _height;
        public float Height
        {
            get { return _height; }
        }

        private float _width;
        public float Width
        {
            get { return _width; }
        }

        private float _scale;
        public float Scale
        {
            get { return _scale; }
            set { _scale = value; }
        }

        private float _x;
        public float X
        {
            get { return _x; }
            set
            {
                _x = value;

                if (_orientation == WallOrientation.Vertical)
                    _x -= _width / 2;
            }
        }

        private float _y;
        public float Y
        {
            get { return _y; }
            set
            {
                _y = value;

                if (_orientation == WallOrientation.Horizontal)
                    _y -= _height / 2;
            }
        }

        private WallOrientation _orientation;
        public WallOrientation Orientation
        {
            get { return _orientation; }
        }

        private Vector2 _direction;
        public Vector2 Direction
        {
            get { return _direction; }
            set { _direction = value; }
        }

        private float _speedFactor;
        public float SpeedFactor
        {
            get { return _speedFactor; }
            set { _speedFactor = value; }
        }

        #endregion

        #region Constructors

        public WallPreview(Vector2 position, float width, WallOrientation orientation)
        {
            _orientation = orientation;

            this.InitializeBounds(position, width);
            this.InitializeTexture();
        }

        #endregion

        #region Private Methods

        private void InitializeBounds(Vector2 position, float width)
        {
            _x = position.X;
            _y = position.Y;
            if (_orientation == WallOrientation.Horizontal)
            {
                _width = width;
                _height = HEIGHT;
                _y -= _height / 2;
            }
            else
            {
                _width = HEIGHT;
                _height = width;
                _x -= _width / 2;
            }
        }

        private void InitializeTexture()
        {
            _texture = Texture2DCreator.FromColor(Color.LightGray, GameResources.Graphics.GraphicsDevice);
        }

        #endregion

        #region Public Methods

        public void Draw(GameTime gameTime)
        {
            GameResources.SpriteBatch.Begin();

            GameResources.SpriteBatch.Draw(texture: _texture,
                destinationRectangle: new Rectangle((int)_x, (int)_y, (int)_width, (int)_height),
                color: Color.White);

            GameResources.SpriteBatch.End();
        }

        #endregion
    }
}